package it.koutifaris.travianmap.view.distances;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.view.distances.DistancesView.DistancesItemView;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.TextView;

public class DistancesItemViewImpl implements DistancesItemView {

	private final View itemView;

	public DistancesItemViewImpl(View itemView) {
		this.itemView = itemView;
	}

	@Override
	public void setTroop(String troop) {
		getTroopView().setText(troop);

	}

	private TextView getTroopView() {
		return (TextView) itemView.findViewById(R.id.distances_item_troop);
	}

	@Override
	public void setTime(float hours) {
		getTimeView().setText(formatInterval(hours));
	}

	private TextView getTimeView() {
		return (TextView) itemView.findViewById(R.id.distances_item_time);
	}

	private static String formatInterval(float hours) {
		int elapsedSeconds = (int) (hours * 3600);
		return DateUtils.formatElapsedTime(elapsedSeconds);
	}

}
